home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / arexx / larp11a.lha / LARP / subs.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-05  |  3.4 KB  |  152 lines

  1. /* subs.c - originally modified from a designer produced file - designer (c) William Connor
  2.  */
  3.  
  4. #include "defs.h"
  5.  
  6. ULONG BevelTags[] = 
  7.     {
  8.     GTBB_Recessed, TRUE,
  9.     GT_VisualInfo, 0,
  10.     TAG_DONE
  11.     };
  12.  
  13. struct Window *Win0 = NULL;
  14. APTR Win0VisualInfo;
  15. UWORD Win0ZoomInfo[4] = { 300, 20, 200, 25 };
  16.  
  17. struct TextAttr topazattr = { (STRPTR)"topaz.font", 8, 0, 65 };
  18. struct TextFont *textfont;
  19.  
  20. struct Library *DiskfontBase = NULL;
  21. struct Library *GadToolsBase = NULL;
  22. struct GfxBase *GfxBase = NULL;
  23. struct IntuitionBase *IntuitionBase = NULL;
  24.  
  25. void RendWindowWin0( struct Window *Win )
  26. {
  27.     UWORD offx = Win->BorderLeft;
  28.     UWORD offy = Win->BorderTop;
  29.     if (Win != NULL) 
  30.     {
  31.         SetAPen(Win->RPort, 0);
  32.         RectFill(Win->RPort, offx+1, offy+1, Win->Width-19, Win->Height-3);
  33.         DrawBevelBoxA( Win->RPort, 5+offx,3+offy,Win->Width-offx-27,Win->Height-offy-8, (struct TagItem *) &BevelTags[0]);
  34.     }
  35. }
  36.  
  37. int OpenWindowWin0( void )
  38. {
  39. struct Screen *Scr;
  40. UWORD offx, offy;
  41. if (Win0 == NULL)
  42. {
  43.     if (NULL != (Scr = LockPubScreen(NULL)))
  44.     {
  45.         offx = Scr->WBorLeft;
  46.         offy = Scr->WBorTop + Scr->Font->ta_YSize+1;
  47.         Win0ZoomInfo[3] = offy + 25;
  48.         if (NULL != ( Win0VisualInfo = GetVisualInfoA( Scr, NULL)))
  49.         {
  50.             if (NULL != (Win0 = OpenWindowTags( NULL, WA_Left, 300,
  51.                             WA_Top, 20,
  52.                             WA_Width, 300+offx,
  53.                             WA_Height, 150+offy,
  54.                             WA_Title, "Little Arexx proggy (LARP)",
  55.                             WA_MinWidth, offx+200,
  56.                             WA_MinHeight, offy+25,
  57.                             WA_MaxWidth, 65535,
  58.                             WA_MaxHeight, 65535,
  59.                             WA_SizeGadget, TRUE,
  60.                             WA_DragBar, TRUE,
  61.                             WA_DepthGadget, TRUE,
  62.                             WA_CloseGadget, TRUE,
  63.                             WA_Activate, TRUE,
  64.                             WA_SmartRefresh, TRUE,
  65.                             WA_AutoAdjust, TRUE,
  66.                             WA_Zoom, Win0ZoomInfo,
  67.                             WA_IDCMP,518,
  68.                             TAG_END)))
  69.             {
  70.                 UnlockPubScreen( NULL, Scr);
  71.                 BevelTags[3] = (ULONG)Win0VisualInfo;
  72.                 textfont = OpenFont( &topazattr);
  73.                 SetFont(Win0->RPort, textfont);
  74.                 RendWindowWin0( Win0 );
  75.                 return( 0L );
  76.             }
  77.             FreeVisualInfo( Win0VisualInfo );
  78.         }
  79.         UnlockPubScreen( NULL, Scr);
  80.     }
  81. }
  82. else
  83. {
  84.     WindowToFront(Win0);
  85.     ActivateWindow(Win0);
  86.     return( 0L );
  87. }
  88. return( 1L );
  89. }
  90.  
  91. void CloseWindowWin0( void )
  92. {
  93.     if (Win0 != NULL)
  94.     {
  95.         CloseWindowSafely( Win0);
  96.         Win0 = NULL;
  97.         if(Win0VisualInfo!=0)
  98.         {
  99.             FreeVisualInfo( Win0VisualInfo);
  100.         }
  101.     }
  102. }
  103.  
  104. int OpenLibs( void )
  105. {
  106. if ( NULL != (DiskfontBase = OpenLibrary("diskfont.library" , 36)))
  107.     if ( NULL != (GadToolsBase = OpenLibrary("gadtools.library" , 37)))
  108.         if ( NULL != (GfxBase = (struct GfxBase * )OpenLibrary("graphics.library" , 37)))
  109.             if ( NULL != (IntuitionBase = (struct IntuitionBase * )OpenLibrary("intuition.library" , 37)))
  110.                 return( 0L );
  111. CloseLibs();
  112. return( 1L );
  113. }
  114.  
  115. void CloseLibs( void )
  116. {
  117. if (NULL != DiskfontBase )
  118.     CloseLibrary( DiskfontBase );
  119. if (NULL != GadToolsBase )
  120.     CloseLibrary( GadToolsBase );
  121. if (NULL != GfxBase )
  122.     CloseLibrary( ( struct Library * )GfxBase );
  123. if (NULL != IntuitionBase )
  124.     CloseLibrary( ( struct Library * )IntuitionBase );
  125. }
  126.  
  127. void StripIntuiMessages( struct MsgPort *mp, struct Window *win)
  128. {
  129. struct IntuiMessage *msg;
  130. struct Node *succ;
  131. msg = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
  132. while (succ = msg->ExecMessage.mn_Node.ln_Succ)
  133.     {
  134.     if (msg->IDCMPWindow == win)
  135.         {
  136.         Remove((struct Node *)msg);
  137.         ReplyMsg((struct Message *)msg);
  138.         }
  139.     msg = (struct IntuiMessage *)succ;
  140.     }
  141. }
  142.  
  143. void CloseWindowSafely( struct Window *win)
  144. {
  145.     Forbid();
  146.     StripIntuiMessages( win->UserPort, win);
  147.     win->UserPort = NULL;
  148.     ModifyIDCMP( win, 0L);
  149.     Permit();
  150.     CloseWindow( win);
  151. }
  152.